#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2021-12-16 13:45
# @Author : huabao.tan
# @File : demo.py
# @Software: PyCharm

from selenium import webdriver
def open_browser(txt):
    try:
        driver = getattr(webdriver, txt)()

    except Exception as e:
        print(e)
        driver = webdriver.Chrome()
    return driver


class Key:

    def __init__(self, txt):
        self.driver = open_browser(txt)

    def max(self):
        self.driver.maximize_window()

    # 访问URL
    def open(self, url):
        self.driver.get(url)

    # 查找元素
    def locator(self, txt):
        return self.driver.find_element_by_xpath(txt)

    # 输入
    def input(self, txt, txt1):
        self.locator(txt).send_keys(txt1)

    # 点击
    def click(self, txt):
        self.locator(txt).click()

    # 等待
    def wait(self, time_):
        sleep(time_)

    # 鼠标向下滚动
    def roll_max(self, txt):
        js = ("var q=document.documentElement.scrollTop='%s'".format(txt))
        self.driver.execute_script(js)
        self.wait(3)

    # 切换表单
    def switch(self, txt):
        self.driver.switch_to.frame(txt)

    # 等待
    def quint(self):
        self.driver.quit()

class Login(Key):

    def __init__(self):
        super(self, Login).__init__()

    def get_url(self):
        self.browser.open('https://kyfw.12306.cn/otn/login/init')


l = Login()
l.get_url()

